'''
    该模块用于绘制perplexity的变化曲线，并
    将绘制结果导出。
'''

import matplotlib.pyplot as plt
from sklearn.decomposition import LatentDirichletAllocation

plt.rcParams['font.sans-serif'] = [u'SimHei']
plt.rcParams['axes.unicode_minus'] = False

def draw_perplexity(X,k_range):
    perplexity=[]
    for k in k_range:
        lda=LatentDirichletAllocation(n_components=k)
        lda.fit(X)
        perplexity.append(lda.perplexity(X))
    plt.plot(k_range,perplexity,'-o')
    plt.title('Perplexity变化曲线')
    plt.xlabel('话题数量')
    plt.ylabel('Perplexity')
    plt.show()


